package com.baseweb.webadmin.core.constants;

import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;

public enum LoginType {
    MOBILE(101,"手机登录"), WEIXIN(201,"微信登录");

    private int code;
    private String name;
    LoginType(int code, String name){
        this.code = code;
        this.name = name;
    }

    public int getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static List<LoginType> getAllData(){
        List<LoginType> result = new ArrayList<LoginType>();
        for (LoginType current : LoginType.values())
        {
            result.add(current);
        }
        return result;
    }

    public static List<LoginType> getUnAuthData(String authListStr){
        List<LoginType> result = new ArrayList<LoginType>();

        for (LoginType current : LoginType.values())
        {
            if (StringUtils.isBlank(authListStr) || authListStr.indexOf(""+current.getCode()) == -1){
                result.add(current);
            }
        }
        return result;
    }

    public static LoginType getNameByCode(int code){
        List<LoginType> allData = getAllData();
        for (LoginType status : allData){
            if (status.getCode() == code){
                return status;
            }
        }
        return null;
    }

}
